package com.ty.controller;

import com.ty.entity.Order;
import com.ty.entity.OrderDetail;
import com.ty.service.OrderDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "订单信息对象功能接口")
@RestController
@RequestMapping("/api/orderdetail")
public class OrderDetailController extends BaseController{

    @Autowired
    OrderDetailService orderDetailService;

    @ApiOperation("订单生成")
    @PostMapping("/orderdetail/insert")
    public ResponseEntity<Integer> insert (OrderDetail orderDetail){
        int rs =orderDetailService.insert(orderDetail);
        return ResponseEntity.ok(rs);
    }

    @ApiOperation("通过ID查询单条数据")
    @GetMapping("/orderdetail/queryById")
    public ResponseEntity<Order> queryById(Integer orderDetail){
        List<Order> orderList = (List<Order>) orderDetailService.queryById(orderDetail);
        return ResponseEntity.ok((Order) orderList);
    }

    @ApiOperation("订单详情信息更新")
    @PostMapping("/orderdetail/update")
    public ResponseEntity<Integer> update(OrderDetail orderDetail){
        int rs = orderDetailService.update(orderDetail);
        return ResponseEntity.ok(rs);
    }

    @ApiOperation("删除订单")
    @DeleteMapping("/orderdetail/delete")
    public ResponseEntity<Boolean> delete(Integer orderDetailId){
        boolean rs =orderDetailService.deleteById(orderDetailId);
        return ResponseEntity.ok(rs);
    }

    @ApiOperation("通过ID查询单条数据")
    @GetMapping("/orderdetail/queryByOrderId")
    public ResponseEntity<Order> queryByOrderId(Integer orderId){
        List<Order> orderList = (List<Order>) orderDetailService.queryById(orderId);
        return ResponseEntity.ok((Order) orderList);
    }


}
